package ro.peter.excel;

import java.io.IOException;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Logger;

import org.apache.poi.openxml4j.exceptions.InvalidFormatException;

import net.sf.jxls.exception.ParsePropertyException;
import net.sf.jxls.transformer.XLSTransformer;

public class ExcelDownload<T> {

	private final static Logger logger = Logger.getAnonymousLogger(); 

	public void downloadExcel(final Collection<T> collection,
			final String templateFileName, final String downloadFileName)
	{
		final Map<String, Object> beans = new HashMap<String, Object>();
		beans.put("col", collection);
		final XLSTransformer transformer = new XLSTransformer();
        try {
			transformer.transformXLS(templateFileName, beans, downloadFileName);
		} catch (ParsePropertyException e) {
			logger.severe("Error parsing properties: " + e.getMessage());
			e.printStackTrace();
		} catch (InvalidFormatException e) {
			logger.severe("Error in format: " + e.getMessage());
			e.printStackTrace();
		} catch (IOException e) {
			logger.severe("IO Error: " + e.getMessage());
			e.printStackTrace();
		}
	}
}
